package com.share.spock.service.impl;

import com.share.spock.mapper.UserInfoMapper;
import com.share.spock.model.UserInfo;
import com.share.spock.service.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author caifan
 * @since 2021/9/29
 * description:
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    @Override
    public void insertUserInfo(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateUserInfo(Long id, String username, String nickname) {
        UserInfo userInfo = userInfoMapper.selectById(id);
        userInfo.setUsername(username);
        updateNickname(userInfo, nickname);
        int update = userInfoMapper.updateById(userInfo);
        System.out.println(update);
        throw new RuntimeException("hhhh");
    }

    private void updateNickname(UserInfo userInfo, String nickname) {
        userInfo.setNickname(nickname);
//        throw new RuntimeException("test");
    }
}
